package com.zqg8512.test.mapper;

import com.zqg8512.test.model.Hello;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.List;

/**
 * @Author zqg
 * @Description
 * @Date 17:19 2019/9/5
 * @Param
 * @return
 **/
@Mapper
@Component
public interface HelloMapper {

    // 插入 并查询id 赋给传入的对象
    @Insert("INSERT INTO test(id, v) VALUES(#{id}, #{v})")
    // @SelectKey(statement = "SELECT seq id FROM sqlite_sequence WHERE (name = 'test')", before = false, keyProperty = "id", resultType = int.class)
    int insert(Hello model);

    // 根据 ID 查询
    @Select("SELECT * FROM test WHERE id=#{id}")
    Hello select(Serializable id);

    // 查询全部
    @Select("SELECT * FROM test")
    List<Hello> selectAll();

    // 更新 value
    @Update("UPDATE test SET v=#{v} WHERE id=#{id}")
    int updateValue(Hello model);

    // 根据 ID 删除
    @Delete("DELETE FROM test WHERE id=#{id}")
    int delete(Serializable id);

}